﻿var examMobile = {};

examMobile.page = {
    init: function () {
        $(".exam-list").css("height", examMobile.examList.examListHeight());
        //查询条件、预约管理界面高度
        $(".main-content").css("height", $(window).height() - $("#header").outerHeight(true));
        //查询条件-内容高度
        $("#search_container_body").css("height", $("#search_container").outerHeight(true) - $("#search_container_footer").outerHeight(true));
        //预设列表内容
        $("#userQuerySet_body").css("height", $("#userQuerySet_container").outerHeight(true) - $("#userQuerySet_container>.search_container_line").outerHeight(true));

        //查询条件中的自定义按钮
        $(".btn-div").click(function () {
            var $this = $(this);
            var eles = $('.btn-div[name="' + $this.attr("name") + '"]');
            var setEleActive = function (checked) {
                for (var i = 0; i < eles.length; i++) {
                    var active = $(eles[i]).attr("class").indexOf("btn-div-active");
                    if (checked) {
                        if (active == -1)
                            $(eles[i]).addClass("btn-div-active").attr("checked", true);
                    } else {
                        if (active > 0)
                            $(eles[i]).removeClass("btn-div-active").attr("checked", false);
                    }
                }
            };
            if ($this.attr("multiple") == "multiple") { //多选
                if ($this.attr("value") == "ALL") { //全选
                    if ($this.attr("class").indexOf("btn-div-active") == -1) {
                        setEleActive(true);
                    } else {
                        setEleActive(false);
                    }
                } else {
                    if ($this.attr("class").indexOf("btn-div-active") == -1) {
                        $this.addClass("btn-div-active").attr("checked", true);
                    } else {
                        $('.btn-div[name="' + $this.attr("name") + '"][value="ALL"]').removeClass("btn-div-active").attr("checked", false);
                        $this.removeClass("btn-div-active").attr("checked", false);
                    }
                }
            } else { 
                var active = $this.attr("class").indexOf("btn-div-active");
                setEleActive(false);
                if (active == -1) {
                    $this.addClass("btn-div-active").attr("checked", true);
                } else {
                    $this.removeClass("btn-div-active").attr("checked", false);
                }
            }
        });

        //扫码
        $('#btnScan').unbind('click');
        $('#btnScan').on('click', function () {
            imcis.scan.init(function (code, type) {
                if (code == "") {
                    schedule.alert("扫码出错，结果为空!");
                    return;
                }
                //bar 条形码
                examMobile.examList.queryReset();
                $("#QueryItemValue").val(code);
                examMobile.examList.search();
            }, function (err) {
                schedule.alert(err);
            });
        });

        //下拉多选
        $('.multipleSel').multiselect({
            buttonWidth: $(".search_container_line").width() - $(".search_container_line_title").outerWidth(true) - 4,
            //dropRight: true,
            dropUp: true,
            checkboxName: 'multiselect[]',
            buttonContainer: '<div class="btn-group btn-multipleSel" />',
            includeSelectAllOption: true, //全选
            selectAllText: '全选',
            enableFiltering: false,
            buttonText: function (options, select) {
                if (options.length === 0) {
                    return '请选择';
                }
                else if (options.length > 3) {
                    return '已选择3个以上选项';
                }
                else {
                    var labels = [];
                    options.each(function () {
                        if ($(this).attr('label') !== undefined) {
                            labels.push($(this).attr('label'));
                        }
                        else {
                            labels.push($(this).html());
                        }
                    });
                    return labels.join(', ') + '';
                }
            },
            onDropdownShown: function (event) {
                var $ul = $(event.target).find('ul');
                var h = $ul.outerHeight(true);
                var w = $ul.outerWidth(true);
                var mh = $ul.parent().find("button").offset().top - $("#header").outerHeight(true) - 10;
                if (h >= mh) {
                    $ul.css({ "height": mh + "px", "overflow": " auto" });
                }
                var top = (h >= mh ? mh : h) + 2;
                $ul.css({ "top": (top * -1) + "px" });

                var mw = $(".search_container_line").width() - 4;
                if (w > $ul.parent().width() || w > mw) {
                    var l = $(".search_container_line_title").outerWidth(true) - 2;
                    $ul.css({ "width": mw + "px", "left": (l * -1) + "px" });
                }
            },
            onDropdownHidden: function (event) {
            }
        });

        //点击搜索图标搜索
        $('.icon-query').unbind('click');
        $('.icon-query').on('click', function () {
            examMobile.examList.search();
        });

        //查询条件设置
        $('#btnQuery').unbind('click');
        $('#btnQuery').on('click', function () {
            $("#search_container").removeClass("slide-right").addClass("slide-left");
            examMobile.event.back(function () {
                $("#search_container").addClass("slide-right").removeClass("slide-left");
            });
        });

        //查询条件设置-预设
        $('#btnPreset').unbind('click');
        $('#btnPreset').on('click', function () {
            $("#userQuerySet_container").removeClass("slide-right").addClass("slide-left");
            examMobile.event.back(function () {
                $("#userQuerySet_container").addClass("slide-right").removeClass("slide-left");
            });
        });

        //查询条件设置-存为预设
        $('.btn-userQuerySet').unbind('click');
        $('.btn-userQuerySet').on('click', function () {
            schedule.promptToExamMobile("存为预设", "请输入预设名", function (val) {
                examMobile.userQuerySet.save(val);
            });
        });

        //查询条件设置-预设-管理
        $('.btn-userQuerySet-manage').unbind('click');
        $('.btn-userQuerySet-manage').on('click', function () {
            if ($(this).html() == "管理") {
                $(this).html("确定");
                $(".userQuerySet-list-tool").show();
                $(".userQuerySet-list span").addClass("userQuerySet-list-span-block");
            } else {
                $(this).html("管理");
                $(".userQuerySet-list-tool").hide();
                $(".userQuerySet-list span").removeClass("userQuerySet-list-span-block");
            }
        });
        
        //查询条件设置-关闭
        $('#search_container_footer .btn-closed').unbind('click');
        $('#search_container_footer .btn-closed').on('click', function () {
            examMobile.event.btnBackHide();
            $("#search_container").addClass("slide-right").removeClass("slide-left");
        });

        //查询条件设置-确定
        $('#search_container_footer .btn-query').unbind('click');
        $('#search_container_footer .btn-query').on('click', function () {
            examMobile.event.btnBackHide();
            $("#search_container").addClass("slide-right").removeClass("slide-left");
            examMobile.examList.search();
        });
        
        //快捷:定义btn-div中某个name的click事件，需要放到btn-div后面
        $('.btn-div[name="QueryTimeDuring"]').click(function () {
            var active = $(this).attr("class").indexOf("btn-div-active");
            if (active == -1) {
                $("#ScheduleStartDate").val("");
                $("#ScheduleEndDate").val("");
            } else {
                examMobile.event.getQueryDateMenuItemClick($(this).attr("id"));
            }
        });

        //下拉刷新
        exam.scrollLoad.pullDown(function (callback) {
            examMobile.examList.reload();
        });

        //上拉加载
        exam.scrollLoad.pullUp(function (callback) {
            examMobile.examList.reloadMore();
        });

        examMobile.userQuerySet.init();
    }
};

examMobile.examList = {
    list: [],
    sort: 'Bed',
    order: 'asc',
    isOnload: false, //是否加载中
    nowPage: 1, //当前页数
    maxPage: 0,
    rows: 20, //加载行数
    examListHeight: function () {
        return $(window).height() - $("#header").outerHeight(true) - $("#search").outerHeight(true);
    },
    queryReset: function () {
        $("#QueryItemValue").val("");
        examMobile.event.multiselectClear("pointOfCare");
        $("#ScheduleStartDate").val("");
        $("#ScheduleEndDate").val("");

        $ele = $('#search_container_body .btn-div');
        for (var i = 0; i < $ele.length; i++) {
            if ($($ele[i]).attr("class").indexOf("btn-div-active") > 0)
                $($ele[i]).removeClass("btn-div-active").attr("checked", false);
        }
    },
    initSearchParams: function (data) {
        var queryCondition = data.QueryCondition;
        if (queryCondition == null) {
            schedule.alert("默认查询条件初始化失败！");
            return false;
        }

        for (var qyId in queryCondition) {
            if (queryCondition[qyId] == null)
                continue;
            var $ele = $("#search_container_body").find('[qy-id="' + qyId + '"]');
            if (["ScheduleSaveStartDate", "RequestedStartDate"].indexOf(qyId) > -1) {
                $ele = $("#search_container_body").find('[qy-id="ScheduleStartDate"]');
            }
            if (["ScheduleSaveEndDate", "RequestedEndDate"].indexOf(qyId) > -1) {
                $ele = $("#search_container_body").find('[qy-id="ScheduleStartDateEnd"]');
            }

            if ($ele.length != 0) {
                switch ($ele[0].nodeName) {
                    case "INPUT":
                        if ($ele.attr("type") == "date") {
                            if ($.trim(queryCondition[qyId]) == "") {
                                $ele.val(queryCondition[qyId]);
                            } else {
                                $ele.val(examMobile.event.dateFullformat(queryCondition[qyId], "yyyy-MM-dd"));
                            }
                        } else if ($ele.attr("type") == "checkbox") {
                            if ($.trim(queryCondition[qyId]) == $ele.val())
                                $ele.prop("checked", true);
                        } else {
                            $ele.val(queryCondition[qyId]);
                        }
                        break;
                    case "SELECT":
                        if ($ele.attr("class").indexOf("multipleSel") > -1) {
                            if (queryCondition[qyId] != null)
                                $ele.multiselect('select', queryCondition[qyId].split(","));

                        } else {
                            $ele.val(queryCondition[qyId]);
                        }
                        break;
                    default:
                        $ele.val(queryCondition[qyId]);
                        break;
                }
            } else {
                $ele = $('#search_container_body .btn-div[name="' + qyId + '"]');
                if ($ele.length == 0)
                    continue;
                var vals = queryCondition[qyId].split(",");
                if ($ele[0].getAttribute("multiple") == "multiple" && vals.length == $ele.length - 1) {
                    $($ele[0]).addClass("btn-div-active").attr("checked", true);
                }
                for (var i = 0; i < vals.length; i++) {
                    $('.btn-div[name="' + qyId + '"][value="' + vals[i] + '"]').addClass("btn-div-active").attr("checked", true);
                }
            }
        }
        if ($.trim(queryCondition.QueryTimeDuring) != "") {
            examMobile.event.getQueryDateMenuItemClick(queryCondition.QueryTimeDuring);
        }
    },
    queryParams: function (params) {
        var transportationMode = examMobile.event.getVal("TransportationMode");
        var dateType = examMobile.event.getVal("QueryTimeType");
        var scheduleStartDate = $.trim($('#ScheduleStartDate').val());
        var scheduleEndDate = $.trim($('#ScheduleEndDate').val());
        var resultStatus = examMobile.event.getVal("ResultStatus", "multiple");
        var serviceSectID = examMobile.event.getVal("ServiceSectID", "multiple");
        var patientClass = examMobile.event.getVal("PatientClass", "multiple");
        var pointOfCareID = $('#pointOfCare').val();
        //病历号/住院号/申请单号/患者姓名
        var queryItemValue = $.trim($('#QueryItemValue').val());

        if (pointOfCareID != null) {
            pointOfCareID = pointOfCareID.join(",");
        }
        if (serviceSectID != null) {
            serviceSectID = serviceSectID.join(",");
        }
        if (resultStatus != null) {
            resultStatus = resultStatus.join(",");
        }
        if (patientClass != null) {
            patientClass = patientClass.join(",");
        }  

        var queryParams = {
            PointOfCareID: pointOfCareID,
            ServiceSectID: serviceSectID,
            ResultStatus: resultStatus,
            TransportationMode: transportationMode,
            Keyword: queryItemValue,
            //QueryItemCode: queryItemCode,
            //QueryItemValue: queryItemValue,
            PatientClass: patientClass,
            requestType: "mobile",
            Page: examMobile.examList.nowPage,
            Rows: examMobile.examList.rows,
            Sort: examMobile.examList.sort,
            Order: examMobile.examList.order
        };

        if (scheduleStartDate != "") {
            scheduleStartDate = scheduleStartDate + " 00:00:00";
        }
        if (scheduleEndDate != "") {
            scheduleEndDate = scheduleEndDate + " 23:59:59";
        }
        switch (dateType) {
            case 'RequestedDate':
                queryParams.RequestedStartDate = scheduleStartDate;
                queryParams.RequestedEndDate = scheduleEndDate;
                break;
            case 'ScheduleDate':
                queryParams.ScheduleStartDate = scheduleStartDate;
                queryParams.ScheduleStartDateEnd = scheduleEndDate;
                break;
            default:
                queryParams.ScheduleSaveStartDate = scheduleStartDate;
                queryParams.ScheduleSaveEndDate = scheduleEndDate;
                break;
        }

        return queryParams;
    },
    checkQueryParamsNotEmpty: function (query) {
        var scheduleStartDate = "", scheduleEndDate = "";
        switch (examMobile.event.getVal("QueryTimeType")) {
            case 'RequestedDate':
                scheduleStartDate = query.RequestedStartDate;
                scheduleEndDate = query.RequestedEndDate;
                break;
            case 'ScheduleDate':
                scheduleStartDate = query.ScheduleStartDate;
                scheduleEndDate = query.ScheduleStartDateEnd;
                break;
            default:
                scheduleStartDate = query.ScheduleSaveStartDate;
                scheduleEndDate = query.ScheduleSaveEndDate;
                break;
        }
        if (scheduleStartDate == "" || scheduleEndDate == "") {
            schedule.alert("查询时间不能为空！");
            return false;
        }
        return true;
    },
    checkComplete: function (row) {
        var completedResultStatus = examMobile.event.getExamCompletedResultStatus(row);
        if (row.ResultStatus == completedResultStatus)
            return true;

        var completedByResultStatus = schedule.GetSysParameterValueByExamRequest({ ServiceSectID: row.ServiceSectID, PatientClass: row.PatientClass }, examCompletedByResultStatus);
        if (completedByResultStatus == "") {
            if (row.ResultStatus == "" || row.ResultStatus == "申请完成" || row.ResultStatus == "申请取消" || row.ResultStatus == "预约完成" || row.ResultStatus == "取消预约" || row.ResultStatus == "取消登记" || row.ResultStatus == "取消检查")
                return false;
        } else if (completedByResultStatus.split(",").indexOf(row.ResultStatus) == -1) {
            return false;
        }

        return null;
    },
    addExamList: function (datas, startIndex) {
        var html = '';
        var index = startIndex;
        for (var i = 0; i < datas.length; i++) {
            var data = {};
            for (var key in datas[i]) {
                data[key] = datas[i][key] == null ? "" : datas[i][key];
            }
            var checkComplete = examMobile.examList.checkComplete(datas[i]);
            var btnChangeState = '';
            if (checkComplete != null) {
                btnChangeState = '<a href="#" class="btn btn-warning btn-backstate ' + (checkComplete ? '' : 'unshow') + '" role="button" index="' + index + '">检查未做</a>' +
                                 '<a href="#" class="btn btn-primary btn-saveState ' + (checkComplete ? 'unshow' : '') + '" role="button" index="' + index + '">检查完成</a>';
            }
            html += ['<li><div class="exam-list-container" index="' + index + '" data-unique="' + data.ObservationUID + '">',
                '            <div class="exam-list-header">',
                '                ' + data.Name + '<span class="seize-6"></span>' + data.Sex + '<span class="seize-6"></span>' + data.Ages,
                                 btnChangeState ,
                '            </div>',
                '            <div>',
                '                <table class="b-table">',
                '                    <tr>',
                '                        <td style="width:22%;text-align:right;">',
                '                            住<span class="seize-6"></span>院<span class="seize-6"></span>号：',
                '                        </td>',
                '                        <td style="width:25%;">',
                '                            <span>' + data.InPatientNO + '</span>',
                '                        </td>',
                '                        <td style="width:17%;text-align:right;">',
                '                            病历号：',
                '                        </td>',
                '                        <td style="width:23%;">',
                '                            <span>' + data.MedRecNO + '</span>',
                '                        </td>',
                '                    </tr>',
                '                    <tr>',
                '                        <td style="width:22%;text-align:right;">',
                '                            病<span class="seize-6"></span>床<span class="seize-6"></span>号：',
                '                        </td>',
                '                        <td style="width:78%;color: #0079FE;font-weight:bold;" colspan="3">',
                '                            <span>' + data.Bed + '</span>',
                '                        </td>',
                '                    </tr>',
                '                    <tr>',
                '                        <td style="width:22%;text-align:right;">',
                '                            病<span class="seize-26"></span>区：',
                '                        </td>',
                '                        <td style="width:78%;" colspan="3">',
                '                            <span>' + data.PointOfCare + '</span>',
                '                        </td>',
                '                    </tr>',
                '                    <tr>',
                '                        <td style="width:22%;text-align:right;">',
                '                            申请时间：',
                '                        </td>',
                '                        <td style="width:78%;" colspan="3">',
                '                            <span>' + data.RequestedDate + '</span>',
                '                        </td>',
                '                    </tr>',
                '                    <tr>',
                '                        <td style="width:22%;text-align:right;">',
                '                            检查项目：',
                '                        </td>',
                '                        <td class="td-content" style="width:78%;" colspan="3">',
                '                            <span class="f-blod">' + data.ServiceSectID + "&nbsp;&nbsp;&nbsp;&nbsp;" + data.ProcedureName + '</span>',
                '                        </td>',
                '                    </tr>',
                '                </table>',
                '            </div>',
                '            <div class="' + (checkComplete != null ? (checkComplete ? "icon-finish" : "icon-unfinish") : "") + '"></div>',
                '        </div></li>'].join("");
            index++;
        }

        $(".exam-list .scrollview").append(html);
        if (examMobile.examList.maxPage == examMobile.examList.nowPage) {
            $(".exam-list .scrollview").children("li:last-child").addClass("loadComplete");
        } else {
            $(".exam-list .scrollview .loadComplete").removeClass("loadComplete");
        }

        //取消检查
        $('.btn-backstate').unbind('click');
        $('.btn-backstate').on('click', function () {
            var $this = $(this);
            var index = $this.attr("index");
            var row = examMobile.examList.list[index];
            var resultStatus = schedule.GetSysParameterValueByExamRequest({ ServiceSectID: row.ServiceSectID, PatientClass: row.PatientClass }, examUnCompletedResultStatus);
            resultStatus = resultStatus == "" ? "预约完成" : resultStatus;

            examMobile.event.backstateComfirm(row, function () {
                examMobile.event.updateExamResultStatus(row, "backstate", resultStatus, function () {
                    $this.hide();
                    var $btn = $this.parent().parent().find(".icon-finish");
                    var checkComplete = examMobile.examList.checkComplete(row);
                    $btn.removeClass("icon-finish");
                    if (checkComplete != null && !checkComplete) {
                        $this.parent().parent().find(".btn-saveState").show();
                        $btn.addClass("icon-unfinish");
                    }
                });
            });

            event.stopPropagation();
        });

        //检查完成
        $('.btn-saveState').unbind('click');
        $('.btn-saveState').on('click', function () {
            var $this = $(this);
            var index = $this.attr("index");
            var row = examMobile.examList.list[index];

            examMobile.event.saveStateComfirm(row, function () {
                examMobile.event.updateExamResultStatus(row, "save", "检查完成", function () {
                    $this.hide();
                    $this.parent().parent().find(".btn-backstate").show();
                    $this.parent().parent().find(".icon-unfinish").addClass("icon-finish").removeClass("icon-unfinish");
                });
            });

            event.stopPropagation();
        });

        //患者详情
        $('.exam-list-container').unbind('click');
        $('.exam-list-container').on('click', examMobile.event.openDetial);
    },
    getExamList: function (query, type, callback, errorback) {
        if (!examMobile.examList.checkQueryParamsNotEmpty(query)) {
            return false;
        }
        imcis.ajax(examPadPath + "GetScheduleQueryResult", query, true, function (ret) {
            if (ret) {
                examMobile.examList.maxPage = ret.total;
                if (type == "search" || type == "reload") {
                    $(".exam-list .scrollview").html("");
                    examMobile.examList.list = [];
                }

                examMobile.examList.list = examMobile.examList.list.concat(ret.rows);
                var statIndex = (query.Page - 1) * query.Rows;
                if (ret.rows.length > 0) {
                    $(".exam-list .scrollview").removeClass("loadNull");
                    examMobile.examList.addExamList(ret.rows, statIndex);
                } else {
                    $(".exam-list .scrollview").addClass("loadNull");
                }

                if (type == "search") {
                    document.getElementsByClassName('content')[0].scrollTop = 0;
                }
                if (callback)
                    callback(ret)
            } else {
                schedule.alert("加载失败！");
                if (errorback)
                    errorback(ret);
            }
        });
    },
    search: function () {
        examMobile.examList.nowPage = 1
        examMobile.examList.getExamList(examMobile.examList.queryParams(), "search");
    },
    reload: function () {
        var queryParams = examMobile.examList.queryParams();
        queryParams.Total = queryParams.Page;   //后端分页查询使用
        queryParams.Rows = queryParams.Page * queryParams.Rows;
        queryParams.Page = 1;
        var error = function () {

        };
        var success = function(){

        };

        examMobile.examList.getExamList(queryParams, "reload", success, error);
    },
    reloadMore: function () {
        if (examMobile.examList.maxPage > examMobile.examList.nowPage) {
            examMobile.examList.nowPage++;
            var queryParams = examMobile.examList.queryParams();
            var error = function () {
                examMobile.examList.nowPage--;
                //数据正在加载，不允许重复查询
                exam.scrollLoad.loadData = false;
                //$('#loadMore').removeClass('type-1');
            };
            var success = function () {
                //数据正在加载，不允许重复查询
                exam.scrollLoad.loadData = false;
                //$('#loadMore').removeClass('type-1');
            };
            //$('#loadMore').addClass('type-1');
            examMobile.examList.getExamList(queryParams, "reloadMore", success, error);
        } 
    }

};

examMobile.userQuerySet = {
    list: [],
    init: function () {
        examMobile.userQuerySet.loadUserQuerySet();
    },
    defaultSeq: '',
    addUserSet: function (queryName, ret) {
        var unshow = $('.btn-userQuerySet-manage').html() == "确定" ? "" : "unshow";
        var spanblock = $('.btn-userQuerySet-manage').html() == "确定" ? "userQuerySet-list-span-block" : "";
        var html = ['<div id="uqs_' + ret.QuerySeq + '" class="userQuerySet-list ' + (ret.DefaultFlag ?  'bg-default' : '')+'">',
            '    <span class="' + spanblock + '">' + queryName + '</span>',
            '    <div class="userQuerySet-list-tool ' + unshow + '">',
            '        <a href="#" class="btn-userqueryset_default" data-id="' + ret.QuerySeq + '">' + (ret.DefaultFlag ? '取消' : '设为默认') + '</a>',
            '        <a href="#" class="btn-userqueryset_delete" data-id="' + ret.QuerySeq + '">删除</a>',
            '    </div>',
            '</div>'].join("");

        $("#userQuerySet_body").append(html);

        if (ret.DefaultFlag) {
            examMobile.userQuerySet.defaultSeq = ret.QuerySeq;
            examMobile.examList.queryReset();
            examMobile.examList.initSearchParams(ret);
            examMobile.examList.search();
        }

        //查询条件设置-预设-设为默认
        $('#uqs_' + ret.QuerySeq + ' .btn-userqueryset_default').unbind('click');
        $('#uqs_' + ret.QuerySeq + ' .btn-userqueryset_default').on('click', examMobile.userQuerySet.setDefault);

        //查询条件设置-预设-删除
        $('#uqs_' + ret.QuerySeq + ' .btn-userqueryset_delete').unbind('click');
        $('#uqs_' + ret.QuerySeq + ' .btn-userqueryset_delete').on('click', examMobile.userQuerySet.setDel);

        //根据预设条件查询
        $('#uqs_' + ret.QuerySeq + ' span').unbind('click');
        $('#uqs_' + ret.QuerySeq + ' span').on('click', function () {
            examMobile.examList.queryReset();
            examMobile.examList.initSearchParams(ret);
            examMobile.examList.search();
            examMobile.event.btnBackHide();
            $("#userQuerySet_container").addClass("slide-right").removeClass("slide-left");
        });
    },
    loadUserQuerySet: function () {
        imcis.ajax(examPadPath + "GetScheduleUserQuerySet", { queryType: "exam_query_pad" }, false, function (ret) {
            if (ret && ret.length > 0) {
                examMobile.userQuerySet.list = [];
                for (var i = 0; i < ret.length; i++) {
                    if (ret[i].DefaultFlag)
                        examMobile.userQuerySet.defaultSeq = ret[i].QuerySeq;
                    var querySet = {
                        QuerySeq: ret[i].QuerySeq,
                        DefaultFlag: ret[i].DefaultFlag,
                        PublicFlag: ret[i].PublicFlag,
                        QueryCondition: imcis.json.parse(ret[i].QueryCondition)
                    };
                    examMobile.userQuerySet.list.push(querySet);
                    examMobile.userQuerySet.addUserSet(ret[i].Name, querySet);
                }
            }
        }, "", function () { });
    },
    save: function (queryName) {
        var queryCondition = examMobile.examList.queryParams();
        if (!examMobile.examList.checkQueryParamsNotEmpty(queryCondition)) {
            return false;
        }
        queryCondition.QueryTimeDuring = examMobile.event.getVal("QueryTimeDuring");
        queryCondition.QueryTimeDuringText = $('.btn-div[name="QueryTimeDuring"][checked="checked"]').html();
        queryCondition.QueryTimeType = examMobile.event.getVal("QueryTimeType");
        queryCondition.QueryTimeTypeText = $("#" + queryCondition.QueryTimeType).html();
        queryCondition = imcis.json.stringify(queryCondition);
        var data = {
            Name: queryName,
            QueryCondition: queryCondition
        };
        imcis.ajax(examPadPath + "SaveQueryUserQuerySet", data, true, function (ret) {
            if (ret) {
                var querySet = {
                    QuerySeq: ret.querySeq,
                    DefaultFlag: ret.DefaultFlag,
                    PublicFlag: ret.PublicFlag,
                    QueryCondition: imcis.json.parse(data.QueryCondition)
                };
                examMobile.userQuerySet.list.push(querySet);
                examMobile.userQuerySet.addUserSet(queryName, querySet);
                schedule.alert("存为预设成功！");
            } else {
                schedule.alert("存为预设失败！");
            }
        });
    },
    //设为默认
    setDefault: function () {
        var $item = $(this);
        var id = $item.attr('data-id');
        imcis.ajax(scheduleCommonPath + "SetDefaultUserQuerySet?seq=" + id + "&t=" + imcis.date.now(), {}, true, function (ret) {
            if (ret) { 
                var $list = $item.parent().parent();
                if (examMobile.userQuerySet.defaultSeq != null && examMobile.userQuerySet.defaultSeq != id) {
                    $('#uqs_' + examMobile.userQuerySet.defaultSeq).removeClass("bg-default").find('.btn-userqueryset_default').html("设为默认");
                }

                if (ret.result.Result.DefaultFlag) {
                    examMobile.userQuerySet.defaultSeq = id;
                    $item.html("取消");
                    $list.addClass("bg-default");
                } else {
                    examMobile.userQuerySet.defaultSeq = null;
                    $item.html("设为默认");
                    $list.removeClass("bg-default");
                }
            } else {
                schedule.alert("设为默认失败！");
            }
        });
        event.stopPropagation();
    },
    //删除预设
    setDel: function () {
        var $item = $(this);
        var id = $item.attr('data-id');
        schedule.comfirm('确定删除预设?', function () {
            imcis.ajax(scheduleCommonPath + "DeleteUserQuerySet?seq=" + id + "&t=" + imcis.date.now(), {}, true, function (ret) {
                if (ret) {
                    $('#uqs_' + id).remove();

                    for (var i = 0; i < examMobile.userQuerySet.list.length; i++) {
                        if (examMobile.userQuerySet.list[i].QuerySeq == id) {
                            examMobile.userQuerySet.list.splice(i, 1);
                            break;
                        }
                    }

                    if (examMobile.userQuerySet.defaultSeq == id) {
                        examMobile.userQuerySet.defaultSeq = null;
                    }
                    schedule.alert("删除预设成功！");
                } else {
                    schedule.alert("删除预设失败！");
                }
            });
        });
        event.stopPropagation();
    }
};

examMobile.event = {
    initData: function (row) {
        var setVal = function (id, val) {
            var $span = $('#detial_container span[data-id="' + id + '"]');
            if ($span.length > 0 && val != null && val != undefined) {
                $span.text(val);
                $span.attr("data-content", val);
            }
        };
        for (var key in row) {
            setVal(key, row[key]);
        }
    },
    getExamCompletedResultStatus: function (row) {
        var completedResultStatus = schedule.GetSysParameterValueByExamRequest({ ServiceSectID: row.ServiceSectID, PatientClass: row.PatientClass }, examCompletedResultStatus);
        if ($.trim(completedResultStatus) == "")
            completedResultStatus = "检查完成";
        return completedResultStatus;
    },
    formatData: function (data) {
        for (var key in data) {
            if (data[key] == null)
                data[key] = "";
        }
        return data;
    },
    backstateComfirm: function (row, callback) {
        examMobile.event.formatData(row);
        var html = '<div class="tip-title">信息确认</div>' +
            '<div style="width:100%;text-align:center;margin-bottom:-10px;">患者【' + row.Name + ' ' + row.Sex + '  ' + row.Ages + ' 病床号：<span style="font-weight: bold;font-size:16px;">' + row.Bed + '</span>】当前为检查完成，您确定取消检查吗？' +
            '<br /><span class="tip-note">注：取消检查此指检查还未做。</span></div>';

        schedule.comfirm(html, function () {
            if (callback)
                callback();
        });
    },
    backstate: function () {
        var $this = $(this);
        var index = $("#detial_container").attr("data-index");
        var row = examMobile.examList.list[index];
        var resultStatus = schedule.GetSysParameterValueByExamRequest({ ServiceSectID: row.ServiceSectID, PatientClass: row.PatientClass }, examUnCompletedResultStatus);
        resultStatus = resultStatus == "" ? "预约完成" : resultStatus;
        examMobile.event.backstateComfirm(row, function () {
            examMobile.event.updateExamResultStatus(row, "backstate", resultStatus, function () {
                $this.hide();
                $("#detial_container .detial-container-line .icon-finish").hide();
                var checkComplete = examMobile.examList.checkComplete(row);
                if (checkComplete != null && !checkComplete) {
                    $this.parent().find(".btn-saveState").show();
                    $("#detial_container .detial-container-line .icon-unfinish").show();
                }

                //切换查询列表的按钮
                var $examlist = $('.exam-list-container[index="' + index + '"]');
                $examlist.find(".btn-backstate").hide();
                var $icon = $examlist.find(".icon-finish");
                $icon.removeClass("icon-finish");
                if (checkComplete != null && !checkComplete) {
                    $examlist.find(".btn-saveState").show();
                    $icon.addClass("icon-unfinish");
                }
            });
        });
        event.stopPropagation();
    },
    saveStateComfirm: function (row, callback) {
        examMobile.event.formatData(row);
        var html = '<div class="tip-title">信息确认</div>' +
            '<div style="width:100%;text-align:center;margin-bottom:-5px;">患者【' + row.Name + ' ' + row.Sex + '  ' + row.Ages + ' 病床号：<span style="font-weight: bold;font-size:16px;">' + row.Bed + '</span>】检查完成吗？</div>';

        schedule.comfirm(html, function () {
            if (callback)
                callback();
        });
    },
    saveState: function () {
        var $this = $(this);
        var index = $("#detial_container").attr("data-index");
        var row = examMobile.examList.list[index];

        examMobile.event.saveStateComfirm(row, function () {
            var completedResultStatus = examMobile.event.getExamCompletedResultStatus(row);
            examMobile.event.updateExamResultStatus(row, "save", completedResultStatus, function () {
                $this.hide();
                $this.parent().find(".btn-backstate").show();
                $("#detial_container .detial-container-line .icon-unfinish").hide();
                $("#detial_container .detial-container-line .icon-finish").show();

                //切换查询列表的按钮
                var $examlist = $('.exam-list-container[index="' + index + '"]');
                $examlist.find(".btn-saveState").hide();
                $examlist.find(".btn-backstate").show();
                $examlist.find(".icon-unfinish").addClass("icon-finish").removeClass("icon-unfinish");
            });
        });
        event.stopPropagation();
    },
    openDetial: function () {
        var $this = $(this);
        var index = $this.attr("index");
        var row = examMobile.examList.list[index];

        //数据赋值
        examMobile.event.initData(row);
        //数据索引值
        $("#detial_container").attr("data-index", index);

        var checkComplete = examMobile.examList.checkComplete(row);
        if (checkComplete != null) {
            if (checkComplete) {
                $("#detial_container .icon-finish,#detial_container .btn-backstate").removeClass("unshow");
            } else {
                $("#detial_container .icon-unfinish,#detial_container .btn-saveState").removeClass("unshow");
            }
        }
        $(".b-header span").html("患者详情");
        //显示
        $("#detial_container").removeClass("slide-right").addClass("slide-left");

        //弹窗提示信息
        $('[data-toggle="popover"]').popover();

        //返回
        examMobile.event.back(function () {
            $('#detial_container .icon-finish,#detial_container .icon-unfinish,#detial_container .btn-backstate,#detial_container .btn-saveState').addClass("unshow");
            $("#detial_container").addClass("slide-right").removeClass("slide-left");
            $('[data-toggle="popover"]').popover("destroy");
            $(".b-header span").html("移动检查");
        });

        //检查未做
        $('.btn-backstate').unbind('click');
        $('.btn-backstate').on('click', examMobile.event.backstate);

        //检查完成
        $('#detial_container .btn-saveState').unbind('click');
        $('#detial_container .btn-saveState').on('click', examMobile.event.saveState);
    },
    //时间字符串输出完整格式如：2021-1-1 -> 2021-01-01
    dateFullformat: function (dataStr, type) {
        var arr = dataStr.split(" ");
        var y = arr[0].split("-");
        for (var i = 0; i < y.length; i++) {
            var item = parseInt(y[i]);
            if (item < 10)
                y[i] = "0" + item;
        }
        var date = y[0] + "-" + y[1] + "-" + y[2];
        if (type == "yyyy-MM-dd")
            return date;
        return date + " " + arr[1];
    },
    multiselectClear: function (id) {
        $("select option").attr("selected", false);
        var $p = $("#" + id).parent();
        //把这个div下的input为checkbox的清空
        $p.find("input[type='checkbox']").each(
            function () { this.checked = false; }
        );
        $p.find(".multiselect-selected-text").text("请选择");
        //把每一个下拉选项的li的class属性的active去掉
        $("li").removeClass("active");
    },
    getVal: function (name, type) {
        var val = "";
        if (type == "multiple") {
            var vals = [];
            var cks = $('.btn-div[name="' + name + '"][checked="checked"]');
            for (var i = 0; i < cks.length; i++) {
                var value = cks[i].getAttribute("value");
                if (value != "ALL")
                    vals.push(value);
            }
            val = vals;
        } else {
            val = $('.btn-div[name="' + name + '"][checked="checked"]').attr("value");
        }
        return val;
    },
    setVal: function (name, val) {

    },
    //时间字符串输出完整格式如：2021-1-1 -> 2021-01-01
    dateFullformat: function (dataStr, type) {
        var arr = dataStr.split(" ");
        var y = arr[0].split("-");
        for (var i = 0; i < y.length; i++) {
            var item = parseInt(y[i]);
            if (item < 10)
                y[i] = "0" + item;
        }
        var date = y[0] + "-" + y[1] + "-" + y[2];
        if (type == "yyyy-MM-dd")
            return date;
        return date + " " + arr[1];
    },
    //点击时间下拉框中的具体时间，为时间控件赋值
    getQueryDateMenuItemClick: function (id) {
        var n, date, endDate; //n星期几减1，date开始时间日期，endDate结束时间日期
        var now = new Date(),
            startTime = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " 00:00:00",
            endTime = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " 23:59:59",
            oneDay = 1000 * 60 * 60 * 24,
            oneHour = 1000 * 60 * 60;
        var idArray = id.split('|');
        if (idArray.length == 2) {
            var idStartTime = '', idEndTime = '';
            if (idArray[0].indexOf('-') > -1) {
                idArray0 = idArray[0].split('-');
            } else if (idArray[0].indexOf('+') > -1) {
                idArray0 = idArray[0].split('+');
            }
            if (idArray[1].indexOf('-') > -1) {
                idArray1 = idArray[1].split('-');
            } else if (idArray[1].indexOf('+') > -1) {
                idArray1 = idArray[1].split('+');
            }
            //开始时间
            switch (idArray0[0]) {
                case "Hour":
                    if (idArray[0].indexOf('-') > -1) {
                        date = new Date(now.getTime() - idArray0[1] * oneHour);
                    } else if (idArray[0].indexOf('+') > -1) {
                        date = new Date(now.getTime() + idArray0[1] * oneHour);
                    }
                    startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":00:00";
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    break;
                case "Today":
                    if (idArray[0].indexOf('-') > -1) {
                        date = new Date(now.getTime() - idArray0[1] * oneDay);
                    } else if (idArray[0].indexOf('+') > -1) {
                        date = new Date(now.getTime() + idArray0[1] * oneDay);
                    }
                    startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 00:00:00";
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    break;
                case "Week":
                    if (idArray[0].indexOf("+") > -1) {
                        date = new Date(now.getTime() + (7 * 24 * 3600 * 1000) * idArray0[1]);
                        var week = date.getDay() == 0 ? 7 : date.getDay();
                        date = new Date(date.getTime() - oneDay * (week - 1));
                        startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 00:00:00";
                    } else if (idArray[0].indexOf("-") > -1) {
                        date = new Date(now.getTime() - (7 * 24 * 3600 * 1000) * idArray0[1]);
                        var week = date.getDay() == 0 ? 7 : date.getDay();
                        date = new Date(date.getTime() - oneDay * (week - 1));
                        startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 00:00:00";
                    }
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    break;
                case "Month":
                    date = new Date(now);
                    if (idArray[0].indexOf('-') > -1) {
                        date.setMonth(parseInt(date.getMonth()) - idArray0[1]);
                    } else if (idArray[0].indexOf('+') > -1) {
                        date.setMonth(parseInt(date.getMonth()) + parseInt(idArray0[1]));
                    }
                    startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-01 00:00:00";
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    break;
                case "Year":
                    date = new Date(now);
                    if (idArray[0].indexOf('-') > -1) {
                        date.setYear(parseInt(date.getFullYear()) - parseInt(idArray0[1]));
                    } else if (idArray[0].indexOf('+') > -1) {
                        date.setYear(parseInt(date.getFullYear()) + parseInt(idArray0[1]));
                    }
                    startTime = date.getFullYear() + "-01-01 00:00:00";
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    break;
                default:
                    break;
            }

            //结束时间
            switch (idArray1[0]) {
                case "Hour":
                    if (idArray[1].indexOf('-') > -1) {
                        date = new Date(now.getTime() - idArray1[1] * oneHour);
                    } else if (idArray[1].indexOf('+') > -1) {
                        date = new Date(now.getTime() + idArray1[1] * oneHour);
                    }
                    endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":59:59";
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                case "Today":
                    if (idArray[1].indexOf('-') > -1) {
                        date = new Date(now.getTime() - idArray1[1] * oneDay);
                    } else if (idArray[1].indexOf('+') > -1) {
                        date = new Date(now.getTime() + idArray1[1] * oneDay);
                    }
                    endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 23:59:59";
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                case "Week":
                    if (idArray[1].indexOf("+") > -1) {
                        date = new Date(now.getTime() + (7 * 24 * 3600 * 1000) * idArray1[1]);
                        var week = date.getDay() == 0 ? 7 : date.getDay();
                        date = new Date(date.getTime() + oneDay * (7 - week));
                        endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 23:59:59";
                    } else if (idArray[1].indexOf("-") > -1) {
                        date = new Date(now.getTime() - (7 * 24 * 3600 * 1000) * idArray1[1]);
                        var week = date.getDay() == 0 ? 7 : date.getDay();
                        date = new Date(date.getTime() + oneDay * (7 - week));
                        endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 23:59:59";
                    }
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                case "Month":
                    date = new Date(now);
                    if (idArray[1].indexOf('-') > -1) {
                        date.setMonth(parseInt(date.getMonth()) - idArray1[1]);
                    } else if (idArray[1].indexOf('+') > -1) {
                        date.setMonth(parseInt(date.getMonth()) + parseInt(idArray1[1]));
                    }
                    var month = date.getMonth();
                    date = new Date(new Date(date.getFullYear(), ++month, 1) - oneDay);
                    endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 23:59:59";
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                case "Year":
                    date = new Date(now);
                    if (idArray[1].indexOf('-') > -1) {
                        date.setYear(parseInt(date.getFullYear()) - parseInt(idArray1[1]));
                    } else if (idArray[1].indexOf('+') > -1) {
                        date.setYear(parseInt(date.getFullYear()) + parseInt(idArray1[1]));
                    }
                    var currentYear = date.getFullYear();
                    date = new Date(new Date(++currentYear, 0, 1) - oneDay);//结束年份的最后一天
                    endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 23:59:59";
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                default:
                    break;
            }
        } else {
            var itemSplit = id.split('-');
            if (itemSplit.length < 2) {
                itemSplit = id.split('+');
            }
            switch (itemSplit[0]) {
                case "All":
                    $("#ScheduleStartDate").val("");
                    $("#ScheduleEndDate").val("");
                    break;
                case "Custom":
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                case "Hour":
                    if (id.indexOf("+") > -1) {
                        date = new Date(now.getTime() + itemSplit[1] * oneHour);
                        endTime = startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
                        startTime = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
                    } else if (id.indexOf("-") > -1) {
                        date = new Date(now.getTime() - itemSplit[1] * oneHour);
                        startTime = startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
                        endTime = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
                    }

                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                case "Today":
                    if (id.indexOf("+") > -1) {
                        date = new Date(now.getTime() + itemSplit[1] * oneDay);
                        endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 23:59:59";
                    } else if (id.indexOf("-") > -1) {
                        date = new Date(now.getTime() - itemSplit[1] * oneDay);
                        startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 00:00:00";
                    }
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));

                    break;
                case "Week":
                    n = (now.getDay() == 0 ? 7 : now.getDay()) - 1;
                    if (id.indexOf("+") > -1) {
                        date = new Date(now.getTime() - n * oneDay);
                        endDate = new Date(now.getTime() + (6 - n) * oneDay + parseInt(itemSplit[1]) * 7 * oneDay);
                        startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 00:00:00";
                        endTime = endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-" + endDate.getDate() + " 23:59:59";
                    } else if (id.indexOf("-") > -1) {
                        date = new Date(now.getTime() - (n + parseInt(itemSplit[1]) * 7) * oneDay);
                        endDate = new Date(now.getTime() + (6 - n) * oneDay);
                        startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 00:00:00";
                        endTime = endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-" + endDate.getDate() + " 23:59:59";
                    }
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                case "Month":
                    startTime = now.getFullYear() + "-" + (now.getMonth() + 1 - parseInt(itemSplit[1])) + "-1 00:00:00";
                    var currentMonth = now.getMonth();
                    endDate = new Date(new Date(now.getFullYear(), ++currentMonth, 1) - oneDay); //本月最后一天
                    endTime = endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-" + endDate.getDate() + " 23:59:59";
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                case "Year":
                    startTime = (now.getFullYear() - parseInt(itemSplit[1])) + "-1-1 00:00:00"; //itemSplit[1]年前年份的第一天
                    var currentYear = now.getFullYear();
                    endDate = new Date(new Date(++currentYear, 0, 1) - oneDay); //本年最后一天
                    endTime = endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-" + endDate.getDate() + " 23:59:59";
                    $('#ScheduleStartDate').val(examMobile.event.dateFullformat(startTime, "yyyy-MM-dd"));
                    $('#ScheduleEndDate').val(examMobile.event.dateFullformat(endTime, "yyyy-MM-dd"));
                    break;
                default:
                    break;
            }
        }
    },
    updateExamResultStatus: function (row, type, resultStatus, callback) {
        var reason = type == "save" ? "移动查房检查完成操作更新" : "移动查房检查未做操作更新";
        var updateExamResultStatusParams = { observationUIDs: row.ObservationUID, reason: reason, resultStatus: resultStatus };
        imcis.ajax(scheduleAbsolutePath + "UpdateExamResultStatus", updateExamResultStatusParams, true, function (ret) {
            try {
                if (ret.success == 0) {
                    row.ResultStatus = ret.resultStatus;
                    if (callback)
                        callback();
                    schedule.alert("保存成功！");
                } else if (ret.success == -1 && ret.errorMsg == "接口状态变更失败") {
                    schedule.alert(ret.errorMsg);
                }
                else {
                    schedule.alert(ret.msg);
                }
            } catch (e) {
                schedule.alert("前端脚本报错");
            }
        }, "", "", function () {//ajax完成

        });
    },
    btnBackHide: function () {
        $('#btnBack').removeClass("fadeIn").addClass("fadeOut");
    },
    //返回按钮
    back: function (callback) {
        $('#btnBack').unbind('click').removeClass("unshow").removeClass("fadeOut").addClass("fadeIn");
        $('#btnBack').on('click', function () {
            var $this = this;
            examMobile.event.btnBackHide();
            if (callback)
                callback($this);
        });
    }
};